package com.ffcs.crmd.tsp.server.jdbc;

import java.sql.Connection;
import java.sql.SQLException;

import com.ffcs.crmd.tsp.server.api.ConnectionProvider;

public class DBConnectionManager {
    
    private static DBConnectionManager instance = new DBConnectionManager();
    
    private ConnectionProvider         provider;
    
    private DBConnectionManager() {
        
    }
    
    public static DBConnectionManager getInstance() {
        return instance;
    }
    
    /**
     * 
     * 功能说明:
     * 
     * @return
     * @throws SQLException
     */
    public Connection getConnection() throws SQLException {
        if (provider == null) {
            throw new SQLException("There is no ConnectionProvider");
        }
        return provider.getConnection();
    }
    
    /**
     * 
     * 功能说明:
     * 
     * @throws SQLException
     */
    public void shutdown() throws SQLException {
        if (provider == null) {
            throw new SQLException("There is no ConnectionProvider");
        }
        provider.shutdown();
        
    }
    
    /**
     * 功能说明: 获取providers
     *
     * @return providers providers
     */
    public ConnectionProvider getProvider() {
        return provider;
    }
    
    /**
     * 功能说明: 设置providers
     *
     * @param providers providers 
     */
    public void setProvider(ConnectionProvider provider) {
        this.provider = provider;
    }
}
